package com.zw.pm.module.config.client;

import com.zw.pm.gen.entity.Client;
import com.zw.pm.gen.entity.Factory;
import com.zw.pm.gen.mapper.ClientMapper;
import com.zw.pm.gen.mapper.FactoryMapper;
import com.zw.pm.module.config.factory.FactoryDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

import static com.zw.pm.constant.Constant.STATUS_NORMAL;

/**
 * @Description: 客户 业务逻辑层
 *
 * @Author: 徐一贺
 * @Date: 2020年3月21日13:11:02
 */
@Service
@Slf4j
public class ClientService {

    @Autowired
    private ClientMapper clientMapper;
    @Autowired
    private ClientDao clientDao;

    /**
     * 按条件查询
     * @param  client
     * @return list
     */
    public List<Client> findClientAll(Client client) {
        client.setDataStatus(1);
        return clientDao.findClientAll(client);
    }

    /**
     * 修改
     *
     * @param client
     * @return 影响行数
     */
    public int updateClient(Client client) {

        return clientMapper.updateByPrimaryKeySelective(client);
    }

    /**
     * 按客户名称查询
     *
     * @param name name
     * @return Factory
     */
    public Client findClientByName(String name) {
        return clientDao.findByClientName(name);
    }

    /**
     * 保存客户信息
     *
     * @param client
     * @return 影响行数
     */
    public int saveClient(Client client) {
        client.setDataStatus(STATUS_NORMAL);
        return clientMapper.insert(client);
    }

    /**
     * 根据ID查询
     * @param id id
     * @return Factory
     */
    public Client getClient(Integer id) {
        return clientMapper.selectByPrimaryKey(id);
    }

    /**
     * 删除
     *
     * @param  client
     * @return 影响行数
     */
    public int delClient(Client client) {
        client.setDataStatus(0);
        return clientMapper.updateByPrimaryKeySelective(client);
    }
}
